package com.rc.net;

import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.util.Log;

import com.rc.SplashScreen.SplashScreenActivity;
import com.rc.activity.dao.DaoMaster;
import com.rc.activity.dao.DaoMaster.DevOpenHelper;
import com.rc.activity.dao.tbl_Item;
import com.rc.activity.dao.tbl_ItemDao;
import com.rc.activity.dao.tbl_Merchant;
import com.rc.activity.dao.tbl_MerchantDao;
import com.rc.activity.dao.tbl_Receipt;
import com.rc.activity.dao.tbl_ReceiptDao;
import com.rc.activity.dao.tbl_Report;
import com.rc.activity.dao.tbl_ReportDao;
import com.rc.activity.dao.tbl_Trip;
import com.rc.activity.dao.tbl_TripDao;
import com.rc.activity.dao.tbl_TripItems;
import com.rc.activity.dao.tbl_TripItemsDao;
import com.rc.activity.provider.Contract;
import com.rc.activity.sync.util.ItemSync;
import com.rc.activity.sync.util.MerchantSync;
import com.rc.activity.sync.util.ReceiptSync;
import com.rc.activity.sync.util.ReportSync;
import com.rc.activity.sync.util.TripItemsSync;
import com.rc.activity.sync.util.TripSync;
import com.rc.db.DatabaseSupport;
import com.rc.fragment.ReportDetailFragment;
import com.rc.object.BaseObject;
import com.rc.object.CategoryObj;
import com.rc.object.CountObj;
import com.rc.object.ItemsObj;
import com.rc.object.MerchantObj;
import com.rc.object.ReceiptObj;
import com.rc.object.ReportObj;
import com.rc.object.SettingsObj;
import com.rc.object.TripItemsObj;
import com.rc.object.TripObj;
import com.rc.object.UserObj;
import com.rc.util.Const;
import com.rc.util.Util;

public class NetSupport extends BaseNetSupport {

	public static ArrayList<BaseObject> api_Login(String UserName,
			String PassWord) {
		ArrayList<BaseObject> arrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		if (UserName != null && PassWord != null) {
			url = Const.apiKey.method_auth + "Email=" + UserName + "&Password="
					+ PassWord;
			result = BaseNetSupport.method_POST(url, "");
			if (result != null) {
				arrBaseObject = BaseNetSupport.parseJson(result, UserObj.keys);
				if (arrBaseObject.size() == 0) {
					return null;
				}
			}

		} else {
			return null;
		}

		return arrBaseObject;
	}

	public static ArrayList<BaseObject> change_pass(String Password,
			String NewPassword, String NewPasswordConfirm, Context ct) {
		ArrayList<BaseObject> arrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		url = Const.apiKey.method_change_pass + "Password=" + Password
				+ "&NewPassword=" + NewPassword + "&NewPasswordConfirm="
				+ NewPasswordConfirm + "";
		result = BaseNetSupport.method_PUT(url, "");
		if (result != null) {
			if (result.indexOf("success") >= 0) {
				BaseObject objBase = new BaseObject();
				arrBaseObject.add(objBase);
			} else {
				String[] keys = { "status", "message" };
				arrBaseObject = BaseNetSupport.parseJson(result, keys);
			}
		}

		return arrBaseObject;
	}

	public static ArrayList<BaseObject> validateTripID(String mTripID,
			Context ct) {
		ArrayList<BaseObject> arrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		url = Const.apiKey.method_get_item_free + "TripID" + mTripID;
		result = BaseNetSupport.method_PUT(url, "");
		if (result != null) {
			if (result.indexOf("success") >= 0) {
				BaseObject objBase = new BaseObject();
				arrBaseObject.add(objBase);
			} else {
				String[] keys = { "status", "message" };
				arrBaseObject = BaseNetSupport.parseJson(result, keys);
			}
		}

		return arrBaseObject;
	}

	public static ArrayList<BaseObject> ocrRequest(String fileName, Context ct) {
		ArrayList<BaseObject> arrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		url = Const.apiKey.method_ocr_request + fileName;
		result = BaseNetSupport.method_POST(url, "");
		if (result != null) {
			if (result.indexOf("success") >= 0) {
				BaseObject objBase = new BaseObject();
				arrBaseObject.add(objBase);
			} else {
				String[] keys = { "status", "message" };
				arrBaseObject = BaseNetSupport.parseJson(result, keys);
			}
		}

		return arrBaseObject;
	}

	public static ArrayList<BaseObject> api_Contact(String fullName,
			String email, String message, String subject) {
		ArrayList<BaseObject> arrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		url = Const.apiKey.method_feedback + "fullname=" + fullName + "&email="
				+ email + "&message=" + message + "&subject=" + subject;
		result = BaseNetSupport.method_POST(url, "");
		if (result != null) {
			arrBaseObject = BaseNetSupport.parseJson(result, UserObj.keys);
		} else {
			return null;
		}

		return arrBaseObject;
	}

	public static ArrayList<BaseObject> api_TripToReport(String mTripID,
			String mDate) {
		ArrayList<BaseObject> arrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		if (mTripID != null && mDate != null) {
			url = Const.apiKey.method_convert_trip_report + "TripID=" + mTripID
					+ "&Date=" + mDate;
			result = BaseNetSupport.method_POST(url, "");
			if (result != null)
				arrBaseObject = BaseNetSupport
						.parseJson(result, ReportObj.keys);

		} else {
			return null;
		}

		return arrBaseObject;
	}

	public static ArrayList<BaseObject> api_RegisterUser(String firstName,
			String lastName, String email, String password,
			String passwordConfirm) {
		ArrayList<BaseObject> arrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		TimeZone tz = TimeZone.getDefault();
		String fields = "&fields=";
		for (String field : ReportObj.keys) {
			fields = fields + field + ",";
		}
		url = Const.apiKey.method_register_user + "FirstName=" + firstName
				+ "&LastName=" + lastName + "&Email=" + email + "&Password="
				+ password + "&PasswordConfirm=" + passwordConfirm
				+ "&Timezone=" + tz.getID() + fields;
		result = BaseNetSupport.method_POST(url, "");
		if (result != null) {
			if (result.indexOf("success") >= 0) {
				BaseObject objBase = new BaseObject();
				arrBaseObject.add(objBase);
			} else {
				return null;
			}
		}
		return arrBaseObject;
	}

	public static ArrayList<BaseObject> get_Receipt(ArrayList<tbl_Trip> arrTrip) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "&fields=";
		for (String field : ReceiptObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		String filedTrip = "";
		if (arrTrip.size() == 0) {
			filedTrip = "&arrayTripID[]=";
		}
		for (int i = 0; i < arrTrip.size(); i++) {
			filedTrip = filedTrip + "arrayTripID[" + i + "]="
					+ arrTrip.get(i).getTripID() + "&";
		}
		url = Const.apiKey.method_get_receipt
				+ "limit=&ReceiptType[0]=3&ReceiptType[1]=4&ReceiptType[2]=2&ReceiptType[3]=6&"
				+ filedTrip + fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, ReceiptObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_ReceiptFree(
			ArrayList<tbl_Receipt> arrReceipts, int limit) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "&fields=";
		for (String field : ReceiptObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		String filedTrip = "";
		for (int i = 0; i < arrReceipts.size(); i++) {
			filedTrip = filedTrip + "arrayNotReceiptID[" + i + "]="
					+ arrReceipts.get(i).getReceiptID() + "&";
		}
		url = Const.apiKey.method_get_receipt
				+ filedTrip
				+ "&ReceiptFree=1&limit="
				+ limit
				+ "&ReceiptType[0]=3&ReceiptType[1]=4&ReceiptType[2]=2&ReceiptType[3]=6&sort=-CreatedTime"
				+ fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, ReceiptObj.keys);
		return arrrBaseObject;
	}

	/**
	 * get receipt from server. insert or update for sqlite
	 */

	public static boolean insert_Update_Receipt_by_ID(String mReceiptID,
			Context context) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "&fields=";
		for (String field : ReceiptObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		url = Const.apiKey.method_get_receipt_by_id + mReceiptID + fields;
		result = BaseNetSupport.method_GET(url, null);
		arrrBaseObject = BaseNetSupport.parseJson(result, ReceiptObj.keys);
		if (arrrBaseObject.size() > 0) {
			if (arrrBaseObject.size() == 0) {
				return false;
			}
			for (int i = 0; i < arrrBaseObject.size(); i++) {
				BaseObject objBase = new BaseObject();
				objBase = arrrBaseObject.get(i);
				tbl_Receipt objReceipt = new tbl_Receipt();
				objReceipt = ReceiptObj.getReceiptbyBaseObject(objBase);

				if (DatabaseSupport.getReceiptByID(objReceipt.getReceiptID(),
						context) != null) {
					int row = context.getContentResolver().update(
							Contract.CONTENT_URI_RECEIPT,
							objReceipt.getContentValues(),
							tbl_ReceiptDao.Properties.ReceiptID.columnName
									+ " = " + objReceipt.getReceiptID(), null);
					if (row > 0) {
						return true;
					}
				} else {
					Uri uri = context.getContentResolver().insert(
							Contract.CONTENT_URI_RECEIPT,
							objReceipt.getContentValues());
					if (uri != null) {
						tbl_Merchant objMerchant = new tbl_Merchant();
						objMerchant = DatabaseSupport.getMerchantByID(
								objReceipt.getMerchantID(), context);
						if (objMerchant == null) {
							ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();
							arrBase = get_MerchantbyID(objReceipt
									.getMerchantID() + "");
							for (BaseObject objBaseObject : arrBase) {
								objMerchant = new tbl_Merchant();
								objMerchant = MerchantObj
										.getObjMerchantByBaseObject(objBaseObject);
								uri = null;
								uri = context.getContentResolver().insert(
										Contract.CONTENT_URI_MERCHANT,
										objMerchant.getContentValues());
								if (uri != null) {
									return true;
								}
							}
						}
					}
				}

			}
		}
		return false;
	}

	/**
	 * get item from server. insert or update for sqlite
	 */

	public static boolean insert_Update_Item_by_ID(String mItemID,
			Context context) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "&fields=";
		for (String field : ItemsObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		url = Const.apiKey.method_get_items_by_id + mItemID + fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null) {
			arrrBaseObject = BaseNetSupport.parseJson(result, ItemsObj.keys);

			if (arrrBaseObject.size() > 0) {
				for (int i = 0; i < arrrBaseObject.size(); i++) {
					BaseObject objBase = new BaseObject();
					objBase = arrrBaseObject.get(i);
					// check duplicate data
					tbl_Item objItem = new tbl_Item();
					objItem = ItemsObj.getObjItemByBaseObject(objBase);
					if (DatabaseSupport.getItemsByItemsID(objItem.getItemID(),
							context) != null) {
						int row = context.getContentResolver().update(
								Contract.CONTENT_URI_ITEMS,
								objItem.getContentValues(),
								tbl_ItemDao.Properties.ItemID.columnName
										+ " = " + objItem.getReceiptID(), null);
						if (row > 0) {
							return true;
						}
					} else {
						Uri uri = context.getContentResolver().insert(
								Contract.CONTENT_URI_ITEMS,
								objItem.getContentValues());
						if (uri != null) {
							ArrayList<BaseObject> arrBaseObjects = new ArrayList<BaseObject>();
							ArrayList<tbl_Item> arrItems = new ArrayList<tbl_Item>();
							arrItems.add(objItem);
							arrBaseObjects = get_TripItemsByItems(arrItems);
							for (BaseObject objBaseObject : arrBaseObjects) {
								tbl_TripItems objTripItems = new tbl_TripItems();
								objTripItems = TripItemsObj
										.getObjTripByBaseObject(objBaseObject);
								context.getContentResolver().insert(
										Contract.CONTENT_URI_TRIP_ITEM,
										objTripItems.getContentValues());
							}
						}
					}
				}

			}
		}
		return false;
	}

	/**
	 * get report from server. insert or update for sqlite
	 */

	public static String insert_Update_Report_by_ID(String mReportID,
			Context context) {
		String msg = "";
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "&fields=";
		for (String field : ReportObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		url = Const.apiKey.method_get_report_by_id + mReportID + fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, ReportObj.keys);
		if (arrrBaseObject.size() > 0) {
			for (int i = 0; i < arrrBaseObject.size(); i++) {
				BaseObject objBase = new BaseObject();
				objBase = arrrBaseObject.get(i);
				// check duplicate data
				tbl_Report objReport = new ReportObj();
				objReport = ReportObj.getReportbyBaseObject(objBase);
				if (objReport == null) {
					return "";
				}
				if (DatabaseSupport.getReportByID(objReport.getReportID(),
						context) != null) {
					int row = context.getContentResolver().update(
							Contract.CONTENT_URI_REPORT,
							objReport.getContentValues(),
							tbl_ReportDao.Properties.ReportID.columnName
									+ " = " + objReport.getReportID(), null);
					if (row > 0) {
						return msg;
					}
				} else {
					Uri uri = context.getContentResolver().insert(
							Contract.CONTENT_URI_REPORT,
							objReport.getContentValues());
					msg = objReport.getApproverEmail()
							+ "\n submitted a report "
							+ objReport.getReference();
					if (uri != null) {
						return msg;
					}
				}

			}
		}
		return msg;
	}

	/**
	 * get trip from server. insert or update for sqlite
	 */

	public static boolean insert_Update_Trip_by_ID(String mTripID,
			Context context) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "&fields=";
		for (String field : TripObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		url = Const.apiKey.method_get_trip_by_id + mTripID + fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, TripObj.keys);
		if (arrrBaseObject.size() > 0) {
			for (int i = 0; i < arrrBaseObject.size(); i++) {
				BaseObject objBase = new BaseObject();
				objBase = arrrBaseObject.get(i);
				// check duplicate data
				tbl_Trip objTrip = new tbl_Trip();
				objTrip = TripObj.getObjTripByBaseObject(objBase);
				if (DatabaseSupport.getTripByID(objTrip.getTripID(), context) != null) {
					int row = context.getContentResolver().update(
							Contract.CONTENT_URI_TRIP,
							objTrip.getContentValues(),
							tbl_TripDao.Properties.TripID.columnName + " = "
									+ objTrip.getTripID(), null);
					if (row > 0) {
						return true;
					}
				} else {
					Uri uri = context.getContentResolver().insert(
							Contract.CONTENT_URI_TRIP,
							objTrip.getContentValues());
					if (uri != null) {
						return true;
					}
				}

			}
		}
		return false;
	}

	public static ArrayList<BaseObject> get_Report(String limit,
			String tripCount, Context ct) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "&fields=";
		for (String field : ReportObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		if ("".equals(limit) || limit == null)
			limit = "20";
		if ("".equals(tripCount) || tripCount == null)
			tripCount = "1";
		Cursor cursor = ct.getContentResolver().query(
				Contract.CONTENT_URI_REPORT, null, null, null, null);
		int count = 0;
		if (cursor != null) {
			count = cursor.getCount();
		}
		url = Const.apiKey.method_get_report + "limit=" + limit + "&offset="
				+ count + "&sort=-CreatedTime&tripCount=" + tripCount + fields;

		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, ReportObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_Trip(ArrayList<tbl_Report> arrReport) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "&fields=";
		String filedReportID = "";

		for (String field : TripObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		if (arrReport.size() == 0) {
			filedReportID = "&arrayReportID[]=";
		}
		for (int i = 0; i < arrReport.size(); i++) {
			filedReportID = filedReportID + "arrayReportID[" + i + "]="
					+ arrReport.get(i).getReportID() + "&";
		}
		url = Const.apiKey.method_get_trip + "limit=&" + filedReportID + fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, TripObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_Trip_free(int limit, Context ct) {
		ArrayList<tbl_Trip> arrTrips = new ArrayList<tbl_Trip>();
		Cursor cursor = ct.getContentResolver().query(
				Contract.CONTENT_URI_TRIP, null, null, null, null);
		arrTrips = tbl_Trip.getObjectbyCursor(cursor);
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "&fields=";
		for (String field : TripObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);

		String filedTrip = "";
		for (int i = 0; i < arrTrips.size(); i++) {
			filedTrip = filedTrip + "arrayNotTripID[" + i + "]="
					+ arrTrips.get(i).getTripID() + "&";
		}

		url = Const.apiKey.method_get_trip + filedTrip + "&tripFree=1&limit="
				+ limit + fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, TripObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_CurrencyConverter(String fromCode,
			String toCode, String purchaseDate) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		url = Const.apiKey.method_convert_currency + "fromCode=" + fromCode
				+ "&toCode=" + toCode + "&purchaseDate=" + purchaseDate;
		result = BaseNetSupport.method_GET(url, null);
		String[] arrString = { "exchangeRate" };
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, arrString);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_setting() {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		url = Const.apiKey.method_settings;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, SettingsObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_Count() {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		url = Const.apiKey.method_get_count;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, CountObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_Merchants(
			ArrayList<tbl_Receipt> arrReceipt) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "fields=";
		for (String field : MerchantObj.keys) {
			fields = fields + field + ",";
		}
		String filedTrip = "";
		for (int i = 0; i < arrReceipt.size(); i++) {
			filedTrip = filedTrip + "arrayReceiptID[" + i + "]="
					+ arrReceipt.get(i).getReceiptID() + "&";
		}
		url = Const.apiKey.method_get_merchant + "limit=&" + filedTrip + fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, MerchantObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_MerchantbyID(String mMerchantID) {
		ArrayList<BaseObject> arrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "fields=";
		for (String field : MerchantObj.keys) {
			fields = fields + field + ",";
		}
		url = Const.apiKey.method_get_merchant + mMerchantID + "?" + fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrBaseObject = BaseNetSupport.parseJson(result, MerchantObj.keys);

		return arrBaseObject;
	}

	public static ArrayList<BaseObject> get_Category() {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "fields=";
		for (String field : CategoryObj.keys) {
			fields = fields + field + ",";
		}
		url = Const.apiKey.method_get_categories + "App=travel_expense&limit=&"
				+ fields;
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, CategoryObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_Items(
			ArrayList<tbl_Receipt> arrReceipts) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "fields=";
		for (String field : ItemsObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		String filedsReceipt = "";
		if (arrReceipts.size() == 0) {
			filedsReceipt = "&ReceiptID[]=";
		}
		for (int i = 0; i < arrReceipts.size(); i++) {
			filedsReceipt = filedsReceipt + "ReceiptID[" + i + "]="
					+ arrReceipts.get(i).getReceiptID() + "&";
		}
		url = Const.apiKey.method_get_items + "limit=&" + filedsReceipt
				+ fields;

		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, ItemsObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_ItemsPending(
			ArrayList<tbl_Trip> arrTrips) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "fields=";
		for (String field : ItemsObj.keys) {
			fields = fields + field + ",";
		}
		fields = fields.substring(0, fields.length() - 1);
		String filedsReceipt = "";
		for (int i = 0; i < arrTrips.size(); i++) {
			filedsReceipt = filedsReceipt + "arrayTripID[" + i + "]="
					+ arrTrips.get(i).getTripID() + "&";
		}
		url = Const.apiKey.method_get_items + "limit=&" + filedsReceipt
				+ fields + "&getTripApprover=1";

		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, ItemsObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_TripItems(
			ArrayList<tbl_Receipt> arrReceipts) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "fields=";
		for (String field : TripItemsObj.keys) {
			fields = fields + field + ",";
		}
		String filedsReceipt = "";
		if (arrReceipts.size() == 0) {
			filedsReceipt = "&arrayReceiptID[]=";
		}
		for (int i = 0; i < arrReceipts.size(); i++) {
			filedsReceipt = filedsReceipt + "arrayReceiptID[" + i + "]="
					+ arrReceipts.get(i).getReceiptID() + "&";
		}
		url = Const.apiKey.method_get_tripitems + "limit=&" + filedsReceipt
				+ fields;

		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport
					.parseJson(result, TripItemsObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_TripItemsByItems(
			ArrayList<tbl_Item> arrItems) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "fields=";
		for (String field : TripItemsObj.keys) {
			fields = fields + field + ",";
		}
		String filedsReceipt = "";
		if (arrItems.size() == 0) {
			filedsReceipt = "&arrayReceiptID[]=";
		}
		for (int i = 0; i < arrItems.size(); i++) {
			filedsReceipt = filedsReceipt + "TripItemID[" + i + "]="
					+ arrItems.get(i).getItemID() + "&";
		}
		url = Const.apiKey.method_get_tripitems + "limit=&" + filedsReceipt
				+ fields;

		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport
					.parseJson(result, TripItemsObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_TripItemsPeding(
			ArrayList<tbl_Trip> arrTrips) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "fields=";
		for (String field : TripItemsObj.keys) {
			fields = fields + field + ",";
		}
		String filedsReceipt = "";
		for (int i = 0; i < arrTrips.size(); i++) {
			filedsReceipt = filedsReceipt + "arrayTripID[" + i + "]="
					+ arrTrips.get(i).getTripID() + "&";
		}
		url = Const.apiKey.method_get_tripitems + "limit=&" + filedsReceipt
				+ fields + "&getTripApprover=1";

		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport
					.parseJson(result, TripItemsObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> get_TripItemsByTripID(long TripID) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		String fields = "fields=";
		for (String field : TripItemsObj.keys) {
			fields = fields + field + ",";
		}
		url = Const.apiKey.method_get_tripitems + "TripID=" + TripID + fields;

		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport
					.parseJson(result, TripItemsObj.keys);
		return arrrBaseObject;
	}

	public static ArrayList<BaseObject> validateImageReceipt(String mReceiptID) {
		ArrayList<BaseObject> arrrBaseObject = new ArrayList<BaseObject>();
		String url;
		String result;
		url = Const.apiKey.method_get_image_receipt + mReceiptID;
		String[] keys = { "image" };
		result = BaseNetSupport.method_GET(url, null);
		if (result != null)
			arrrBaseObject = BaseNetSupport.parseJson(result, keys);
		return arrrBaseObject;
	}

	/**
	 * delete multireceipt
	 */

	public static boolean delete_receipt(List<Long> lReceiptID, Context ct) {
		String url;
		String result;
		String fields = "";
		for (int i = 0; i < lReceiptID.size(); i++) {
			fields = fields + "ReceiptID[" + i + "]=" + lReceiptID.get(i) + "&";
		}
		fields = fields.substring(0, fields.length() - 1);
		url = Const.apiKey.method_get_receipt + fields;
		result = BaseNetSupport.method_Delete(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, ReceiptSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < lReceiptID.size(); i++) {
				String status = arrBase.get(i).getParam(ReceiptSync.keys[0]);
				long receiptID = lReceiptID.get(i);
				if ("success".equals(status)) {
					ct.getContentResolver().delete(
							Contract.CONTENT_URI_RECEIPT,
							tbl_ReceiptDao.Properties.ReceiptID.columnName
									+ " = " + receiptID, null);
				} else {
					Cursor cursor = ct
							.getContentResolver()
							.query(Contract.CONTENT_URI_RECEIPT,
									null,
									tbl_ReceiptDao.Properties.ReceiptID.columnName
											+ " = '"
											+ lReceiptID.get(i)
											+ "' and "
											+ tbl_ReceiptDao.Properties.IsDelete.columnName
											+ " = '1'", null, null);
					ArrayList<tbl_Receipt> arrReceipt = new ArrayList<tbl_Receipt>();
					arrReceipt = tbl_Receipt.getObjectbyCursor(cursor);
					for (tbl_Receipt objReceipt : arrReceipt) {
						objReceipt.setBug(arrBase.get(i).getParam(
								ReceiptSync.keys[2]));
						objReceipt.setIsDelete("");

						ct.getContentResolver().update(
								Contract.CONTENT_URI_RECEIPT,
								objReceipt.getContentValues(),
								tbl_ReceiptDao.Properties.ReceiptID.columnName
										+ " = " + receiptID, null);
					}

				}

			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;

	}

	/**
	 * delete multireceipt
	 */

	public static boolean delete_device(String deviceToken, Activity ct) {
		String url;
		String result;
		url = Const.apiKey.method_register_deviced + "DeviceToken="
				+ deviceToken;
		result = BaseNetSupport.method_Delete(url, "");
		if (result != null)
			if (result.indexOf("success") >= 0) {
				SQLiteDatabase db;
				DevOpenHelper helper = new DaoMaster.DevOpenHelper(ct,
						Const.DATABASE_NAME, null);
				db = helper.getWritableDatabase();
				DaoMaster.dropAllTables(db, false);
				DaoMaster.createAllTables(db, false);
				SplashScreenActivity.callIntent(ct);
				return true;
			}
		return false;

	}

	/**
	 * insert multireceipt
	 * 
	 * Receipt[0][PurchaseTime]=2004-02-12&Receipt[0][MerchantID]=1&Receipt[0][
	 * id]=12345&Receipt[1][id]=123456&Receipt[1][PurchaseTime]=2014-02-23&
	 * Receipt
	 * [1][MerchantID]=2&Receipt[2][id]=23564&Receipt[2][PurchaseTime]=2014
	 * -05-24&Receipt[2][MerchantID]=111
	 */
	public static boolean insert_receipt(ArrayList<tbl_Receipt> arrReceipt,
			Context ct) {
		String url;
		String result;
		String fields = "";

		fields = parseReceipt(arrReceipt);
		url = Const.apiKey.method_insert_receipt + fields;
		result = BaseNetSupport.method_POST(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, ReceiptSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < arrReceipt.size(); i++) {
				String status = arrBase.get(i).getParam(ReceiptSync.keys[0]);
				long receiptID = arrReceipt.get(i).getReceiptID();
				if ("success".equals(status)) {
					arrReceipt.get(i).setReceiptID(
							arrBase.get(i).getParamLong(ReceiptSync.keys[1]));
					arrReceipt.get(i).setIsCreate("");
				} else {
					arrReceipt.get(i).setBug(
							arrBase.get(i).getParam(ReceiptSync.keys[2]));
					arrReceipt.get(i).setIsCreate("");
				}
				if (ct.getContentResolver().update(
						Contract.CONTENT_URI_RECEIPT,
						arrReceipt.get(i).getContentValues(),
						tbl_ReceiptDao.Properties.ReceiptID.columnName + " = "
								+ receiptID, null) != -1) {
					ArrayList<tbl_Item> arrItem = new ArrayList<tbl_Item>();
					arrItem = DatabaseSupport
							.getItemsByReceiptID(receiptID, ct);
					for (tbl_Item objItem : arrItem) {
						objItem.setIsUpdate("1");
						objItem.setReceiptID(arrReceipt.get(i).getReceiptID());
						ct.getContentResolver().update(
								Contract.CONTENT_URI_ITEMS,
								objItem.getContentValues(),
								tbl_ItemDao.Properties.ItemID.columnName
										+ " = " + objItem.getItemID(), null);
					}
				}
			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;
	}

	/**
	 * insert multireceipt
	 * 
	 * Receipt[0][PurchaseTime]=2004-02-12&Receipt[0][MerchantID]=1&Receipt[0][
	 * id]=12345&Receipt[1][id]=123456&Receipt[1][PurchaseTime]=2014-02-23&
	 * Receipt
	 * [1][MerchantID]=2&Receipt[2][id]=23564&Receipt[2][PurchaseTime]=2014
	 * -05-24&Receipt[2][MerchantID]=111
	 */
	public static boolean update_receipt(ArrayList<tbl_Receipt> arrReceipt,
			Context ct) {
		String url;
		String result;
		String fields = "";

		fields = parseReceipt(arrReceipt);
		url = Const.apiKey.method_insert_receipt + fields;
		result = BaseNetSupport.method_PUT(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();
		if (result == null) {
			return false;
		}
		arrBase = BaseNetSupport.parseJson(result, ReceiptSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < arrReceipt.size(); i++) {
				String status = arrBase.get(i).getParam(MerchantSync.keys[0]);
				long receiptID = arrReceipt.get(i).getReceiptID();
				if ("success".equals(status)) {
					arrReceipt.get(i).setIsUpdate("");
				} else {
					arrReceipt.get(i).setBug(
							arrBase.get(i).getParam(ReceiptSync.keys[2]));
					arrReceipt.get(i).setIsUpdate("");
				}
				ct.getContentResolver().update(
						Contract.CONTENT_URI_RECEIPT,
						arrReceipt.get(i).getContentValues(),
						tbl_ReceiptDao.Properties.ReceiptID.columnName + " = "
								+ receiptID, null);
			}
		}
		if (result != null) {
			if (result.indexOf("success") >= 0) {
				return true;
			}
		}

		return false;
	}

	public static boolean updateTripItems(
			ArrayList<tbl_TripItems> arrTripItems, Context ct) {
		String url;
		String result;
		String fields = "";

		fields = parseTripItem(arrTripItems);
		url = Const.apiKey.method_multi_trip_item + fields;
		result = BaseNetSupport.method_PUT(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();
		if (result == null) {
			return false;
		}
		arrBase = BaseNetSupport.parseJson(result, TripItemsSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < arrTripItems.size(); i++) {
				String status = arrBase.get(i).getParam(TripItemsSync.keys[0]);
				long tripItemID = arrTripItems.get(i).getTripItemID();
				if ("success".equals(status)) {
					arrTripItems.get(i).setIsUpdate("");
				}
				ct.getContentResolver().update(
						Contract.CONTENT_URI_TRIP_ITEM,
						arrTripItems.get(i).getContentValues(),
						tbl_TripItemsDao.Properties.TripItemID.columnName
								+ " = " + tripItemID, null);
			}
		}
		if (result != null) {
			if (result.indexOf("success") >= 0) {
				return true;
			}
		}

		return false;
	}

	public static void register_device(Context ct, String deviceToken) {
		String url = Const.apiKey.method_register_deviced + "DeviceToken="
				+ deviceToken + "&DeviceType=ANDROID";
		String result = BaseNetSupport.method_POST(url, "");
		Log.d("HTA - register device", result);
	}

	/**
	 * Parse String Receipt.
	 * 
	 * @param objReceipt
	 *            Receipt need parse
	 */
	public static String parseReceipt(ArrayList<tbl_Receipt> arrReceipt) {
		String fields = "";
		for (int i = 0; i < arrReceipt.size(); i++) {
			tbl_Receipt objReceipt = arrReceipt.get(i);
			if (objReceipt != null) {
				// fields = fields
				// + ReceiptObj.PURCHASE_TIME
				// + Util.formateDateFromstring("dd-MM-yyyy",
				// "yyyy-MM-dd", objReceipt.getPurchaseTime()
				// + "&");
				String indexReceipt = Const.KEY_RECEIPT + "[" + i + "]";
				String purchaseTime = indexReceipt
						+ "["
						+ ReceiptObj.PURCHASE_TIME
						+ "]="
						+ Util.formateDateFromstring("dd-MM-yyyy",
								"yyyy-MM-dd", objReceipt.getPurchaseTime());
				String merchantId = "";
				if (objReceipt.getMerchantID() != 0) {
					merchantId = "&" + indexReceipt + "["
							+ ReceiptObj.MERCHANT_ID + "]="
							+ objReceipt.getMerchantID();
				}

				String receiptID = indexReceipt + "[" + ReceiptObj.RECEIPT_ID
						+ "]=" + objReceipt.getReceiptID();
				String total = indexReceipt + "[" + ReceiptObj.TOTAL + "]="
						+ objReceipt.getTotal();
				String discount = indexReceipt + "[" + ReceiptObj.DISCOUNT
						+ "]=" + objReceipt.getDiscount();
				String subtotal = indexReceipt + "[" + ReceiptObj.SUBTOTAL
						+ "]=" + objReceipt.getSubtotal();
				String tax = indexReceipt + "[" + ReceiptObj.TAX + "]="
						+ objReceipt.getTax();
				String currencyCode = indexReceipt + "["
						+ ReceiptObj.CURRENCY_CODE + "]="
						+ objReceipt.getCurrencyCode();
				String exchangeRate = indexReceipt + "["
						+ ReceiptObj.EXCHANGE_RATE + "]="
						+ objReceipt.getExchangeRate();
				String createDate = indexReceipt + "["
						+ ReceiptObj.CREATED_TIME + "]="
						+ objReceipt.getCreatedTime();
				String receiptType = indexReceipt + "["
						+ ReceiptObj.RECEIPT_TYPE + "]="
						+ objReceipt.getReceiptType();
				String merchantCountry = indexReceipt + "["
						+ ReceiptObj.MERCHANT_COUNTRY + "]="
						+ objReceipt.getMerchantCountry();
				fields = fields + purchaseTime + merchantId + "&" + receiptID
						+ "&" + total + "&" + discount + "&" + subtotal + "&"
						+ tax + "&" + currencyCode + "&" + exchangeRate + "&"
						+ createDate + "&" + receiptType + "&"
						+ merchantCountry + "&";

			}

		}
		fields = fields.substring(0, fields.length() - 1);
		fields = Util.decodeURL(fields);
		return fields;
	}

	/**
	 * Parse String TripItems.
	 * 
	 * @param objTripItem
	 *            TripItemsObj need parse
	 */
	public static String parseTripItem(ArrayList<tbl_TripItems> arrTripItems) {
		String fields = "";
		for (int i = 0; i < arrTripItems.size(); i++) {
			tbl_TripItems objTripItem = arrTripItems.get(i);
			if (objTripItem != null) {
				// create index
				String indexReceipt = Const.KEY_TRIPITEM + "[" + i + "]";

				String tripItemID = indexReceipt + "["
						+ TripItemsObj.TRIP_ITEM_ID + "]="
						+ objTripItem.getTripItemID();
				String tripID = indexReceipt + "[" + TripItemsObj.TRIP_ID
						+ "]=" + objTripItem.getTripID();
				String isClaimed = indexReceipt + "[" + TripItemsObj.IS_CLAIMED
						+ "]=" + objTripItem.getIsClaimed();
				String isApproved = indexReceipt + "["
						+ TripItemsObj.IS_APPROVED + "]="
						+ objTripItem.getIsApproved();
				String claimed = indexReceipt + "[" + TripItemsObj.CLAIMED
						+ "]=" + objTripItem.getClaimed();
				String approved = indexReceipt + "[" + TripItemsObj.APPROVED
						+ "]=" + objTripItem.getApproved();
				fields = fields + tripItemID + "&" + tripID + "&" + isClaimed
						+ "&" + isApproved + "&" + claimed + "&" + approved
						+ "&";
			}
		}
		fields = fields.substring(0, fields.length() - 1);
		fields = Util.decodeURL(fields);
		return fields;
	}

	// Report .

	/**
	 * Delete list of report .
	 * 
	 * @param reportIds
	 *            List Id of reports need delete
	 */
	public static boolean deleteReport(List<Long> reportIds, Context ct) {
		String url;
		String result;
		String fields = "";
		for (int i = 0; i < reportIds.size(); i++) {
			fields = fields + "ReportID[" + i + "]=" + reportIds.get(i) + "&";
		}
		fields = fields.substring(0, fields.length() - 1);
		url = Const.apiKey.method_get_report + fields;
		result = BaseNetSupport.method_Delete(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, ReportSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < reportIds.size(); i++) {
				String status = arrBase.get(i).getParam(ReportSync.keys[0]);
				long reportID = reportIds.get(i);
				if ("success".equals(status)) {
					ct.getContentResolver().delete(
							Contract.CONTENT_URI_REPORT,
							tbl_ReportDao.Properties.ReportID.columnName
									+ " = " + reportID, null);
					ArrayList<tbl_Trip> arrTrips = new ArrayList<tbl_Trip>();
					arrTrips = DatabaseSupport.getTripbyReportID(reportID + "",
							ct);
					for (tbl_Trip objTrip : arrTrips) {
						reportID = 0;
						objTrip.setReport_ID(reportID);
						objTrip.setIsUpdate("1");
						ct.getContentResolver().update(
								Contract.CONTENT_URI_TRIP,
								objTrip.getContentValues(),
								tbl_TripDao.Properties.TripID.columnName
										+ " = " + objTrip.getTripID(), null);
					}
				} else {
					tbl_Report objReport = new tbl_Report();
					objReport = DatabaseSupport.getReportByID(reportID, ct);
					if (objReport == null) {
						return true;
					}
					objReport.setBug(arrBase.get(i)
							.getParam(ReportSync.keys[2]));
					objReport.setIsDelete("");

					ct.getContentResolver().update(
							Contract.CONTENT_URI_REPORT,
							objReport.getContentValues(),
							tbl_ReportDao.Properties.ReportID.columnName
									+ " = " + reportID, null);
				}

			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;

	}

	/**
	 * Delete list of tripitem .
	 * 
	 * @param reportIds
	 *            List Id of reports need delete
	 */
	public static boolean deleteTripItem(List<Long> tripItemIds, Context ct) {
		String url;
		String result;
		String fields = "";
		for (int i = 0; i < tripItemIds.size(); i++) {
			fields = fields + "TripItemID[" + i + "]=" + tripItemIds.get(i)
					+ "&";
		}
		fields = fields.substring(0, fields.length() - 1);
		url = Const.apiKey.method_multi_trip_item + fields;
		result = BaseNetSupport.method_Delete(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, TripItemsSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < tripItemIds.size(); i++) {
				String status = arrBase.get(i).getParam(TripItemsSync.keys[0]);
				long tripItems = tripItemIds.get(i);
				if ("success".equals(status)) {
					ct.getContentResolver().delete(
							Contract.CONTENT_URI_TRIP_ITEM,
							tbl_TripItemsDao.Properties.TripItemID.columnName
									+ " = " + tripItems, null);
				}
			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;
	}

	/**
	 * Insert Reports
	 */
	public static boolean insertReports(ArrayList<tbl_Report> arrReport,
			Context ct) {
		String url;
		String result;
		String fields = "";

		fields = parseReport(arrReport, ct);
		url = Const.apiKey.method_mutil_report + fields;
		result = BaseNetSupport.method_POST(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, ReportSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				for (tbl_Report objReport : arrReport) {
					objReport.setIsCreate("");
					objReport.setIsUpdate("");
					objReport.setBug("Bug");
					ct.getContentResolver().update(
							Contract.CONTENT_URI_REPORT,
							objReport.getContentValues(),
							tbl_ReportDao.Properties.ReportID.columnName
									+ " = " + objReport.getReportID(), null);
				}
				return false;
			}
			for (int i = 0; i < arrReport.size(); i++) {
				String status = arrBase.get(i).getParam(ReportSync.keys[0]);
				long reportID = arrReport.get(i).getReportID();
				if ("success".equals(status)) {
					arrReport.get(i).setReportID(
							arrBase.get(i).getParamLong(ReportSync.keys[1]));
					arrReport.get(i).setIsCreate("");
					ArrayList<tbl_Trip> arrTrips = new ArrayList<tbl_Trip>();
					arrTrips = DatabaseSupport.getTripbyReportID(
							arrReport.get(i).getReportID() + "", ct);
					for (tbl_Trip objTrip : arrTrips) {
						objTrip.setReport_ID(arrBase.get(i).getParamLong(
								ReportSync.keys[1]));
						objTrip.setIsUpdate("1");
						ct.getContentResolver().update(
								Contract.CONTENT_URI_TRIP,
								objTrip.getContentValues(),
								tbl_TripDao.Properties.TripID.columnName
										+ " = " + objTrip.getTripID(), null);
					}
				} else {

					arrReport.get(i).setBug(
							arrBase.get(i).getParam(ReportSync.keys[2]));
					arrReport.get(i).setIsCreate("");
				}
				ArrayList<tbl_Trip> arrTrips = new ArrayList<tbl_Trip>();
				arrTrips = DatabaseSupport.getTripbyReportID(reportID + "", ct);
				for (tbl_Trip objTrip : arrTrips) {
					objTrip.setReport_ID(arrReport.get(i).getReportID());
					ct.getContentResolver().update(
							Contract.CONTENT_URI_TRIP,
							objTrip.getContentValues(),
							tbl_TripDao.Properties.TripID.columnName + " = "
									+ objTrip.getTripID(), null);
				}
				ct.getContentResolver().update(
						Contract.CONTENT_URI_REPORT,
						arrReport.get(i).getContentValues(),
						tbl_ReportDao.Properties.ReportID.columnName + " = "
								+ reportID, null);
				Intent it = new Intent("update.report.detail");
				it.putExtra(ReportDetailFragment.REPORT_ID_LOCAL, reportID);
				it.putExtra(ReportDetailFragment.REPORT_ID_SERVER, arrReport
						.get(i).getReportID());
				ct.sendBroadcast(it);
			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;
	}

	/**
	 * Update Report .
	 */
	public static boolean updateReports(ArrayList<tbl_Report> arrReport,
			Context ct) {
		String url;
		String result;
		String fields = "";

		fields = parseReport(arrReport, ct);
		url = Const.apiKey.method_mutil_report + fields;
		result = BaseNetSupport.method_PUT(url, "");
		Log.d("ewewe", "ok " + result);
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		if (result == null) {
			return false;
		}
		arrBase = BaseNetSupport.parseJson(result, ReportSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < arrReport.size(); i++) {
				String status = "";
				String bug = "";
				long reportID = arrReport.get(i).getReportID();
				if (arrBase.size() > 0) {
					status = arrBase.get(i).getParam(ReportSync.keys[0]);
					bug = arrBase.get(i).getParam(ReportSync.keys[2]);
				}
				if (!"success".equals(status)) {
					arrReport.get(i).setBug(bug);
				}
				arrReport.get(i).setIsUpdate("");
				ct.getContentResolver().update(
						Contract.CONTENT_URI_REPORT,
						arrReport.get(i).getContentValues(),
						tbl_ReportDao.Properties.ReportID.columnName + " = "
								+ reportID, null);
			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;
	}

	/**
	 * Parse Report
	 */
	public static String parseReport(ArrayList<tbl_Report> arrReport, Context ct) {
		String fields = "";
		for (int i = 0; i < arrReport.size(); i++) {
			tbl_Report objReport = arrReport.get(i);
			if (objReport != null) {
				// fields = fields
				// + ReceiptObj.PURCHASE_TIME
				// + Util.formateDateFromstring("dd-MM-yyyy",
				// "yyyy-MM-dd", objReceipt.getPurchaseTime()
				// + "&");
				String indexReport = Const.KEY_REPORT + "[" + i + "]";
				String title = indexReport + "[" + ReportObj.TITLE + "]="
						+ objReport.getTitle();
				String date = indexReport
						+ "["
						+ ReportObj.DATE
						+ "]="
						+ Util.formateDateFromstring("dd-MM-yyyy",
								"yyyy-MM-dd", objReport.getDate());
				String reference = indexReport + "[" + ReportObj.REFERENCE
						+ "]=" + objReport.getReference();
				String isSubmitted = indexReport + "[" + ReportObj.IS_SUBMITTED
						+ "]=" + objReport.getIsSubmitted();
				String isArchived = indexReport + "[" + ReportObj.IS_ARCHIVED
						+ "]=" + objReport.getIsArchived();

				String approverEmail = "";
				approverEmail = objReport.getApproverEmail();
				if (approverEmail != null) {
					if (!"".equals(approverEmail)) {
						approverEmail = indexReport + "["
								+ ReportObj.APPROVER_EMAIL + "]="
								+ objReport.getApproverEmail();
						;
					}
				}

				String id = indexReport + "[" + ReportObj.REPORT_ID + "]="
						+ objReport.getReportID();
				String reportType = indexReport + "[" + ReportObj.REPORT_TYPE
						+ "]=" + objReport.getReportType();
				String approved = indexReport + "[" + ReportObj.APPROVED + "]="
						+ objReport.getApproved();
				String isApproved = indexReport + "[" + ReportObj.IS_APPROVED
						+ "]=" + objReport.getIsApproved();
				String claimed = indexReport + "[" + ReportObj.CLAIMNED + "]="
						+ objReport.getClaimed();

				String tripID = "";
				ArrayList<tbl_Trip> arrTrips = new ArrayList<tbl_Trip>();
				arrTrips = DatabaseSupport.getTripbyReportID(
						objReport.getReportID() + "", ct);
				if (arrTrips != null) {
					if (arrTrips.size() > 0)
						tripID = indexReport + "[" + TripObj.TRIP_ID + "]="
								+ arrTrips.get(0).getTripID();
				}
				if (approverEmail == null) {
					approverEmail = "";
				}
				fields = fields + title + "&" + date + "&" + reference + "&"
						+ isSubmitted + "&" + approverEmail + "&" + id + "&"
						+ isArchived + "&" + reportType + "&" + approved + "&"
						+ isApproved + "&" + claimed + "&" + tripID + "&";

			}

		}
		fields = fields.substring(0, fields.length() - 1);
		fields = Util.decodeURL(fields);
		return fields;
	}

	// End report .

	// Trip

	/**
	 * Delete list of Trip .
	 * 
	 * @param tripIds
	 *            List Id of trips need delete
	 */
	public static boolean deleteTrips(List<Long> tripIds, Context ct) {
		String url;
		String result;
		String fields = "";
		for (int i = 0; i < tripIds.size(); i++) {
			fields = fields + "TripID[" + i + "]=" + tripIds.get(i) + "&";
		}
		fields = fields.substring(0, fields.length() - 1);
		url = Const.apiKey.method_get_trip + fields;
		result = BaseNetSupport.method_Delete(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, TripSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < tripIds.size(); i++) {
				String status = arrBase.get(i).getParam(TripSync.keys[0]);
				long tripID = tripIds.get(i);
				if ("success".equals(status)) {
					ct.getContentResolver().delete(
							Contract.CONTENT_URI_TRIP,
							tbl_TripDao.Properties.TripID.columnName + " = "
									+ tripID, null);
					ArrayList<tbl_Item> arrItem = new ArrayList<tbl_Item>();
					arrItem = DatabaseSupport.getItemsByTripID(tripID, ct);
					for (tbl_Item objItem : arrItem) {
						objItem.setCategorizeStatus(0);
						tripID = 0;
						objItem.setTripID(tripID);
						objItem.setCategoryID(tripID);
						ct.getContentResolver().update(
								Contract.CONTENT_URI_ITEMS,
								objItem.getContentValues(),
								tbl_ItemDao.Properties.ItemID.columnName
										+ " = " + objItem.getItemID(), null);
						tbl_TripItems objTripItem = new tbl_TripItems();
						objTripItem = DatabaseSupport.getTripItemsByID(
								objItem.getItemID(), ct);
						if (objTripItem != null) {
							objTripItem.setIsDelete("1");
							ct.getContentResolver()
									.update(Contract.CONTENT_URI_TRIP_ITEM,
											objTripItem.getContentValues(),
											tbl_TripItemsDao.Properties.TripItemID.columnName
													+ " = "
													+ objTripItem
															.getTripItemID(),
											null);
						}

					}
				} else {
					Cursor cursor = ct.getContentResolver().query(
							Contract.CONTENT_URI_TRIP,
							null,
							tbl_TripDao.Properties.TripID.columnName + " = '"
									+ tripID + "'", null, null);
					ArrayList<tbl_Trip> arrTrip = new ArrayList<tbl_Trip>();
					arrTrip = tbl_Trip.getObjectbyCursor(cursor);
					for (tbl_Trip objTrip : arrTrip) {
						objTrip.setBug(arrBase.get(i)
								.getParam(TripSync.keys[2]));
						objTrip.setIsDelete("");
						ct.getContentResolver().update(
								Contract.CONTENT_URI_TRIP,
								objTrip.getContentValues(),
								tbl_TripDao.Properties.TripID.columnName
										+ " = " + tripID, null);
					}

				}

			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;

	}

	/**
	 * Insert multi Trips
	 */
	public static ArrayList<BaseObject> insertTrips(ArrayList<tbl_Trip> arrTrip) {
		String url;
		String result;
		String fields = "";

		fields = parseTrips(arrTrip);
		url = Const.apiKey.method_multi_trip + fields;
		result = BaseNetSupport.method_POST(url, "");
		ArrayList<BaseObject> arrObjBase = new ArrayList<BaseObject>();
		if (result != null)
			arrObjBase = BaseNetSupport.parseJson(result, TripSync.keys);
		Log.d("ewewe", "ok " + result);

		return arrObjBase;
	}

	/**
	 * Insert multi TripItem
	 */
	public static ArrayList<BaseObject> insertTripItem(
			ArrayList<tbl_TripItems> arrTripItems) {
		String url;
		String result;
		String fields = "";

		fields = parseTripItem(arrTripItems);
		url = Const.apiKey.method_multi_trip_item + fields;
		result = BaseNetSupport.method_POST(url, "");
		ArrayList<BaseObject> arrObjBase = new ArrayList<BaseObject>();
		if (result != null)
			arrObjBase = BaseNetSupport.parseJson(result, TripSync.keys);
		Log.d("ewewe", "ok " + result);

		return arrObjBase;
	}

	/**
	 * Update Trips.
	 */
	public static boolean updateTrips(ArrayList<tbl_Trip> arrTrip) {
		String url;
		String result;
		String fields = "";

		fields = parseTrips(arrTrip);
		url = Const.apiKey.method_multi_trip + fields;
		result = BaseNetSupport.method_PUT(url, "");
		Log.d("ewewe", "ok " + result);
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;
	}

	/**
	 * Parse Trips
	 */
	public static String parseTrips(ArrayList<tbl_Trip> arrTrips) {
		String fields = "";
		for (int i = 0; i < arrTrips.size(); i++) {
			tbl_Trip objTrip = arrTrips.get(i);
			if (objTrip != null) {
				// fields = fields
				// + ReceiptObj.PURCHASE_TIME
				// + Util.formateDateFromstring("dd-MM-yyyy",
				// "yyyy-MM-dd", objReceipt.getPurchaseTime()
				// + "&");
				String indexTrip = Const.KEY_TRIP + "[" + i + "]";
				String name = indexTrip + "[" + TripObj.NAME + "]="
						+ objTrip.getName();
				String departure = indexTrip + "[" + TripObj.DEPARTURE + "]="
						+ objTrip.getDeparture();
				String nameArrival = indexTrip + "[" + TripObj.ARRIVAL + "]="
						+ objTrip.getArrival();
				String reportID;
				if (objTrip.getReport_ID() == 0) {
					reportID = "";
				} else {
					reportID = indexTrip + "[" + TripObj.REPORT_ID + "]="
							+ objTrip.getReport_ID();
				}

				String startDate = indexTrip
						+ "["
						+ TripObj.START_DATE
						+ "]="
						+ Util.formateDateFromstring("dd-MM-yyyy",
								"yyyy-MM-dd", objTrip.getStartDate());
				String reference = indexTrip + "[" + TripObj.REFERENCE + "]="
						+ objTrip.getReference();
				String endDate = indexTrip
						+ "["
						+ TripObj.END_DATE
						+ "]="
						+ Util.formateDateFromstring("dd-MM-yyyy",
								"yyyy-MM-dd", objTrip.getEndDate());
				String tripId = indexTrip + "[" + TripObj.TRIP_ID + "]="
						+ objTrip.getTripID();
				String amount = indexTrip + "[" + TripObj.AMOUNT + "]="
						+ objTrip.getAmount();

				fields = fields + name + "&" + departure + "&" + nameArrival
						+ "&" + startDate + "&" + reference + "&" + endDate
						+ "&" + tripId + "&" + reportID + "&" + amount;

			}

		}
		fields = fields.substring(0, fields.length() - 1);
		fields = Util.decodeURL(fields);
		return fields;
	}

	// end trip

	// Items
	/**
	 * Delete list of item .
	 * 
	 * @param reportIds
	 *            List Id of reports need delete
	 */
	public static boolean deleteItems(List<Long> itemIds, Context ct) {
		String url;
		String result;
		String fields = "";
		for (int i = 0; i < itemIds.size(); i++) {
			fields = fields + "ItemID[" + i + "]=" + itemIds.get(i) + "&";
		}
		fields = fields.substring(0, fields.length() - 1);
		url = Const.apiKey.method_get_items + fields;
		result = BaseNetSupport.method_Delete(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, ItemSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < itemIds.size(); i++) {
				String status = arrBase.get(i).getParam(ItemSync.keys[0]);
				long itemID = itemIds.get(i);
				if ("success".equals(status)) {
					ct.getContentResolver().delete(
							Contract.CONTENT_URI_ITEMS,
							tbl_ItemDao.Properties.ItemID.columnName + " = "
									+ itemID, null);
				} else {
					Cursor cursor = ct
							.getContentResolver()
							.query(Contract.CONTENT_URI_ITEMS,
									null,
									tbl_ItemDao.Properties.ItemID.columnName
											+ " = '"
											+ itemIds.get(i)
											+ "' and "
											+ tbl_ItemDao.Properties.IsDelete.columnName
											+ " = '1'", null, null);
					for (tbl_Item objItem : tbl_Item.getObjectbyCursor(cursor)) {
						if (objItem != null) {
							objItem.setBug(arrBase.get(i).getParam(
									ItemSync.keys[2]));
							objItem.setIsDelete("");

							ct.getContentResolver().update(
									Contract.CONTENT_URI_ITEMS,
									objItem.getContentValues(),
									tbl_ItemDao.Properties.ItemID.columnName
											+ " = " + itemID, null);
						}
					}

				}

			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;

	}

	/**
	 * Insert items
	 */
	public static boolean insertItems(ArrayList<tbl_Item> arrItem, Context ct) {
		String url;
		String result;
		String fields = "";

		fields = parseItems(arrItem);
		url = Const.apiKey.method_multi_items + fields;
		result = BaseNetSupport.method_POST(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, ItemSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < arrItem.size(); i++) {
				String status = arrBase.get(i).getParam(ItemSync.keys[0]);
				long itemID = arrItem.get(i).getItemID();
				if ("success".equals(status)) {
					arrItem.get(i).setItemID(
							arrBase.get(i).getParamLong(ItemSync.keys[1]));
					arrItem.get(i).setIsCreate("");
				} else {
					arrItem.get(i).setBug(
							arrBase.get(i).getParam(ItemSync.keys[2]));
					arrItem.get(i).setIsCreate("");
				}
				ct.getContentResolver().update(
						Contract.CONTENT_URI_ITEMS,
						arrItem.get(i).getContentValues(),
						tbl_ItemDao.Properties.ItemID.columnName + " = "
								+ itemID, null);
			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;
	}

	/**
	 * Update items.
	 */
	public static boolean updateItems(ArrayList<tbl_Item> arrItem, Context ct) {
		String url;
		String result;
		String fields = "";

		fields = parseItems(arrItem);
		url = Const.apiKey.method_multi_items + fields;
		result = BaseNetSupport.method_PUT(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		if (result == null) {
			return false;
		}
		arrBase = BaseNetSupport.parseJson(result, ItemSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < arrItem.size(); i++) {
				String status = arrBase.get(i).getParam(ItemSync.keys[0]);
				long itemID = arrItem.get(i).getItemID();
				if ("success".equals(status)) {
					arrItem.get(i).setIsUpdate("");
				} else {
					arrItem.get(i).setBug(
							arrBase.get(i).getParam(ItemSync.keys[2]));
					arrItem.get(i).setIsUpdate("");
				}
				ct.getContentResolver().update(
						Contract.CONTENT_URI_ITEMS,
						arrItem.get(i).getContentValues(),
						tbl_ItemDao.Properties.ItemID.columnName + " = "
								+ itemID, null);
			}
		}
		if (result != null) {
			if (result.indexOf("success") >= 0) {
				return true;
			}
		}

		return false;
	}

	/**
	 * Parse items
	 */
	public static String parseItems(ArrayList<tbl_Item> arrItem) {
		String fields = "";
		for (int i = 0; i < arrItem.size(); i++) {
			tbl_Item objItem = arrItem.get(i);
			if (objItem != null) {
				// fields = fields
				// + ReceiptObj.PURCHASE_TIME
				// + Util.formateDateFromstring("dd-MM-yyyy",
				// "yyyy-MM-dd", objReceipt.getPurchaseTime()
				// + "&");
				String indexItem = Const.KEY_ITEM + "[" + i + "]";
				String receiptID = indexItem + "[" + ItemsObj.RECEIPT_ID + "]="
						+ objItem.getReceiptID();
				String categoryID = indexItem + "[" + ItemsObj.CATEGORY_ID
						+ "]=" + objItem.getCategoryID();

				String name = indexItem + "[" + ItemsObj.NAME + "]="
						+ objItem.getName();
				String amount = indexItem + "[" + ItemsObj.AMOUNT + "]="
						+ objItem.getAmount();
				String itemId = indexItem + "[" + ItemsObj.ITEM_ID + "]="
						+ objItem.getItemID();

				fields = fields + receiptID + "&" + name + "&" + amount + "&"
						+ itemId + "&" + categoryID + "&";

			}

		}
		fields = fields.substring(0, fields.length() - 1);
		fields = Util.decodeURL(fields);
		return fields;
	}

	// End item

	// Trip items

	// End trip items

	// Merchant .
	/**
	 * Insert Merchant. TODO
	 */
	public static boolean insertMerchant(ArrayList<tbl_Merchant> arrMerchant,
			Context ct) {
		String url;
		String result;
		String fields = "";
		fields = parseMerchant(arrMerchant);

		fields = fields.substring(0, (fields.length() - 1));
		url = Const.apiKey.method_insert_merchant + fields;
		result = BaseNetSupport.method_POST(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, MerchantSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < arrMerchant.size(); i++) {
				String status = arrBase.get(i).getParam(MerchantSync.keys[0]);
				long merchantID = arrMerchant.get(i).getMerchantID();
				if ("success".equals(status)) {
					arrMerchant.get(i).setMerchantID(
							arrBase.get(i).getParamLong(MerchantSync.keys[1]));
					arrMerchant.get(i).setIsCreate("");
					tbl_Receipt objReceipt = new tbl_Receipt();
					objReceipt = DatabaseSupport.getReceiptByMerchantID(
							merchantID, ct);
					objReceipt.setMerchantID(arrBase.get(i).getParamLong(
							MerchantSync.keys[1]));
					ct.getContentResolver().update(
							Contract.CONTENT_URI_RECEIPT,
							objReceipt.getContentValues(),
							tbl_ReceiptDao.Properties.ReceiptID.columnName
									+ " = " + objReceipt.getReceiptID(), null);
				} else {
					arrMerchant.get(i).setBug(
							arrBase.get(i).getParam(MerchantSync.keys[2]));
					arrMerchant.get(i).setIsCreate("");
				}
				ct.getContentResolver().update(
						Contract.CONTENT_URI_MERCHANT,
						arrMerchant.get(i).getContentValues(),
						tbl_MerchantDao.Properties.MerchantID.columnName
								+ " = " + merchantID, null);

			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;
	}

	/**
	 * Update Merchant. TODO
	 */
	public static boolean updateMerchant(ArrayList<tbl_Merchant> arrMerchant,
			Context ct) {
		String url;
		String result;
		String fields = "";

		fields = parseMerchant(arrMerchant);

		fields = fields.substring(0, (fields.length() - 1));
		url = Const.apiKey.method_insert_merchant + fields;
		result = BaseNetSupport.method_PUT(url, "");
		ArrayList<BaseObject> arrBase = new ArrayList<BaseObject>();

		arrBase = BaseNetSupport.parseJson(result, ItemSync.keys);
		if (arrBase != null) {
			if (arrBase.size() == 0) {
				return false;
			}
			for (int i = 0; i < arrMerchant.size(); i++) {
				String status = arrBase.get(i).getParam(MerchantSync.keys[0]);
				long merchantID = arrMerchant.get(i).getMerchantID();
				if ("success".equals(status)) {
					arrMerchant.get(i).setIsUpdate("");
				} else {
					arrMerchant.get(i).setBug(
							arrBase.get(i).getParam(MerchantSync.keys[2]));
					arrMerchant.get(i).setIsUpdate("");
				}
				ct.getContentResolver().update(
						Contract.CONTENT_URI_MERCHANT,
						arrMerchant.get(i).getContentValues(),
						tbl_MerchantDao.Properties.MerchantID.columnName
								+ " = " + merchantID, null);
			}
		}
		if (result != null)
			if (result.indexOf("success") >= 0) {
				return true;
			}
		return false;
	}

	/**
	 * Parse merchant . : Name, Logo, Address, City, State, ZipCode,
	 * CountryCode, PhoneNumber, NaicsCode, SicCode, MccCode
	 * 
	 */
	public static String parseMerchant(ArrayList<tbl_Merchant> arrMerchant) {
		String fields = "";
		for (int i = 0; i < arrMerchant.size(); i++) {
			tbl_Merchant objMerchant = arrMerchant.get(i);
			if (objMerchant != null) {
				String indexItem = Const.KEY_MERCHANT + "[" + i + "]";
				String id = indexItem + "[" + MerchantObj.MERCHANT_ID + "]="
						+ objMerchant.getMerchantID();
				String name = indexItem + "[" + MerchantObj.MERCHANT_NAME
						+ "]=" + objMerchant.getName();
				String logo = indexItem + "[" + MerchantObj.MERCHANT_LOGO
						+ "]=" + objMerchant.getLogo();
				String address = indexItem + "[" + MerchantObj.MERCHANT_ADDRESS
						+ "]=" + objMerchant.getAddress();
				String city = indexItem + "[" + MerchantObj.MERCHANT_CITY
						+ "]=" + objMerchant.getCity();
				String state = indexItem + "[" + MerchantObj.MERCHANT_STATE
						+ "]=" + objMerchant.getState();
				String zipCode = indexItem + "[" + MerchantObj.ZIP_CODE + "]="
						+ objMerchant.getZipCode();
				String phoneNumber = indexItem + "["
						+ MerchantObj.MERCHANT_PHONE + "]="
						+ objMerchant.getPhoneNumber();
				fields = id + "&" + name + "&" + logo + "&" + address + "&"
						+ city + "&" + state + "&" + zipCode + "&"
						+ phoneNumber + "&";

				// String naicsCode = indexItem + "[" +
				// MerchantObj.MERCHANT_NAME
				// + "]=" + objItem.getName();
				// String sicCode = indexItem + "[" + MerchantObj.MERCHANT_NAME
				// + "]=" + objItem.getName();
				// String mccCode = indexItem + "[" + MerchantObj.MERCHANT_NAME
				// + "]=" + objItem.getName();

				// fields = name + "&" + logo + "&" + address + "&" + city + "&"
				// + state + "&" + zipCode + "&" + countryCode + "&"
				// + phoneNumber + "&" + naicsCode + "&" + sicCode + "&"
				// + mccCode;

			}

		}
		fields = fields.substring(0, fields.length() - 1);
		fields = Util.decodeURL(fields);
		return fields;
	}
	// End merchant .
}
